package com.thz.houserental.infrastructure.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestUtils {
    public static String getMethodAndUrl(HttpServletRequest request) {
        return request.getMethod() + " " + request.getServletPath();
    }
    
    public static HttpServletRequest getSimpleMethod(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    public static String getSimpleRequest() {
        HttpServletRequest request = getSimpleMethod();
        if (request == null) return null;
        
        return request.getMethod() + " " + request.getServletPath();
    }

    public static String getMethod(){
        HttpServletRequest request = getSimpleMethod();
        return request.getMethod();
    }

    public static String getURL(){
        HttpServletRequest request = getSimpleMethod();
        return String.valueOf(request.getRequestURL());
    }
}
